﻿#region Using Directives

using System;

using QuickDev.Caching;
using QuickDev.Model;

#endregion

namespace ReturnDB.Taobao.WebApp
{
    public class Global : System.Web.HttpApplication
    {
        /// <summary>
        /// Handles the Start event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void Application_Start( object sender, EventArgs e )
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        /// <summary>
        /// Handles the PreRequestHandlerExecute event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void Application_PreRequestHandlerExecute( object sender, EventArgs e )
        {
            SiteSettings siteSettings = null;
            try
            {
                siteSettings = SiteSettingsCache.GetCachedModel();
            }
            catch ( Exception )
            {
                //swallow it - probably no connection string during install
            }

            string cultureName = ""; //default this. TODO: Get this into installer?
            if ( siteSettings != null )
            {
                cultureName = siteSettings.Language == null ? cultureName : siteSettings.Language;
            }
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture( cultureName );
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
        }
    }
}
